#include <plugin/util/AbstractSecurityContext.h>

#include <memory.h>

namespace antu
{
namespace plugin
{
AbstractSecurityContext::AbstractSecurityContext(const QString& moduleCode, const char* p, size_t length)
    : m_sModuleCode(moduleCode),
      m_pSecurityToken(nullptr),
      m_iLength(length)
{
    Q_ASSERT(p != nullptr);

    if (length != 0 && p != nullptr)
        this->m_iLength = length;

    if (p != nullptr)
    {
        this->m_pSecurityToken = new char[this->m_iLength + 1];
        memset(this->m_pSecurityToken, 0, this->m_iLength + 1);
        memcpy(this->m_pSecurityToken, p, this->m_iLength);
    }
}

AbstractSecurityContext::~AbstractSecurityContext()
{
    if (this->m_pSecurityToken != nullptr)
        delete [] this->m_pSecurityToken;
}

bool NullSecurityContext::isAllowed(const QString &) const
{
    return true;
}

}
}

